﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DTO;

namespace DAO
{
    public class PhanQuyenDAO
    {

        ConnectDB conn = new ConnectDB();
        string str;
        //Load dữ liệu
        public DataTable Load_PhanQuyen()
        {
            return conn.LayDuLieu("select *from PhanQuyen");
        }
        //lay Ma Quyen
        public DataTable MQ()
        {
            return conn.LayDuLieu("select MaQuyen from Quyen ");
        }
        //lay Ma Nhom Nguoi Dung
        public DataTable MNND()
        {
            return conn.LayDuLieu("select MaNhomNguoiDung from NhomNguoiDung");
        }
        //Lay Ma Nhan Vien
        public DataTable MNV()
        {
            return conn.LayDuLieu("select MaNV from NhanVien");
        }
        // Insert và Update
        public void IsUp_PhanQuyen(PhanQuyenDTO p, Boolean flag)
        {
            string MaQuyen = p.MaQuyen ;
            string MaNhomNguoiDung  = p.MaNhom ;
            string MaNV = p.MaNV ;
            string MatKhau = p.MatKhau ;
            string TenDangNhap = p.TenDangNhap ;
            
            if (flag == true)
            {//(MaQuyen, MaNhomNguoiDung, MaNV, MatKhau, TenDangNhap)
                str = "INSERT PhanQuyen (MaQuyen, MaNhomNguoiDung, MaNV, MatKhau, TenDangNhap) VALUES('" + MaQuyen + "','" + MaNhomNguoiDung+ "'," + MaNV  + "," + MatKhau  + ",'" + TenDangNhap  + ")";
            }
            else if (flag == false)
            {
                str = "UPDATE PhanQuyen SET MaQuyen ='" + MaQuyen + "', MaNhomNguoiDung ='" + MaNhomNguoiDung  + "', MaNV =" + MaNV  + ", MatKhau =" + MatKhau  + ", TenDangNhap ='" + TenDangNhap  + " WHERE MaQuyen='" + MaQuyen + "'and MaNhomNguoiDung = '"+ MaNhomNguoiDung  +"'";
            }
            conn.excute(str);

        }
        //delete
        public void Del_PhanQuyen(PhanQuyenDTO p)
        {
            string MaQuyen = p.MaQuyen ;
            string MaNhomNguoiDung = p.MaNhom;
            str = "DELETE PhanQuyen  WHERE MaQuyen='" + MaQuyen + "'and MaNhomNguoiDung = '"+ MaNhomNguoiDung  +"'";
            conn.excute(str);
        }
       
    }
}
